package com.koron.css2.clientCenter.impl;


import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.CtmInfoBean;
import com.koron.css2.clientCenter.mapper.CtmInfoMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import com.mysql.cj.util.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 并户，根据身份证号查询客户信息
 * 
 * @author 甄玉晴
 *
 */
public class ClientInfoList implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", List.class);
			CtmInfoBean bean = JsonUtils.objectToPojo(req.getData(), CtmInfoBean.class);
			//身份证号不能为空
			if(bean==null||StringUtils.isNullOrEmpty(bean.getCertNo())) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "查询失败,缺少查询条件", null);
			}
			CtmInfoMapper mapper = factory.getMapper(CtmInfoMapper.class);
			// 查询列表
			List<CtmInfoBean> ctmInfo = mapper.querySameAccountClient(bean.getCertNo());//查询有用户的客户信息
			for (CtmInfoBean ctmInfoBean : ctmInfo) {
				if (org.apache.commons.lang3.StringUtils.isNotBlank(ctmInfoBean.getCtmType())) {
					ctmInfoBean.setCtmType(Tools.getDicNameByCodeAndValue(factory, "CTT", ctmInfoBean.getCtmType()));
				}
			}
			info.setData(ctmInfo);
			return info;
		} catch (Exception e) {
			logger.error("用户变更信息查询失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
